package org.example.maven.mapper;

import org.apache.ibatis.annotations.*;
import org.example.maven.pojo.role.AddRole;
import org.example.maven.pojo.role.RoleListTable;
import org.example.maven.pojo.role.SearchRole;

import java.util.List;

@Mapper
public interface RoleMapper {
    //获取所有的角色信息
    @Select("select id,role_name,created_at as time,role_key,status from role")
    List<RoleListTable> getAllRoleList();

    //根据id获取角色的信息

    List<RoleListTable> getSpecieRole(SearchRole searchRole);

    //根据id获取待编辑的角色信息
    @Select("select * from role where id=#{id}")
    AddRole getEditRole(Integer id);

    //判断添加的角色是否存在
    @Select("select role_name from role where role_name=#{roleName}")
    String getRoleName(String roleName);

    //添加角色
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("INSERT INTO role(role_name,role_key,description,status,created_at) values (#{roleName},#{roleKey},#{description},#{status},#{time})")
    void addRole(AddRole addRole);

    //添加角色和权限的绑定
    void addRolePermission(@Param("roleId")String id,@Param("permIds")String[] permission);

    //获取角色的总数
    Integer getRoleCount(SearchRole searchRole);

    //根据id删除岗位
    void deleteRoleById(String [] id);

    //根据id更新角色信息
    void updateRoleById(AddRole addRole);

    //获取角色对应的权限
    @Select("SELECT perm_id from role_permission where role_id=#{id}")
    String[] getRolePermission(Integer id);

    //删除对应角色的权限
    @Delete("delete from role_permission where role_id=#{id}")
    void deleteRolePermission(Integer id);

    //获取角色多选框的选项
    @Select("select id as value,role_name as label from role")
    List<org.example.maven.pojo.utils.Select> getRoleSelect();
}
